package org.ohuyo.libra.client.session;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;
import org.ohuyo.libra.client.exception.LibraClientException;
import org.ohuyo.libra.client.service.ClientService;

/**
 * session������
 * 
 * @author rabbit
 * 
 */
public abstract class AbstractLibraSession implements LibraSession,
Serializable {
	/**
    *
    */
	private static final long serialVersionUID = -64924443627538956L;

	/**
	 * ��½��ˮ
	 */
	private String loginTicket;

	/**
	 * Ӧ�ô���
	 */
	private String appCode;

	/**
	 * Ӧ��Ʊ��
	 */
	private String appTicket;

	/**
	 * �ͻ���Ʊ��
	 */
	private String clientTicket;

	/**
	 * �ͻ��˵�ַ <br>
	 * the Internet Protocol (IP) address of the client or last proxy that sent
	 * the request
	 */
	private String remoteAddr;

	/**
	 * �ͻ��ڵ�½ʱʹ�õĵ�ַ<br>
	 * the Internet Protocol (IP) address of the client or last proxy that sent
	 * the request
	 */
	private String loginAddr;

//	/**
//	 * Ӧ��IP
//	 */
//	private transient volatile String appIp;
//	/**
//	 * Ӧ�ö˿�
//	 */
//	private transient volatile int appPort;

	/**
	 * �ͻ�ID
	 */
	private String custId;

	/**
	 * ����
	 */
	private String attachment;

	/**
	 * �ͻ�ID����
	 */
	private String custIdType;

	/**
	 * ��תƱ��(���棬����Ӧ�ø�������Ч)
	 */
	private String jumpTicket;

	protected abstract ClientService getClientService();

	// ----------------------------------
	final public void setAttribute(String targetAppCode, String key,
			String value) throws LibraClientException {
		if (StringUtils.isBlank(targetAppCode)) {
			throw new LibraClientException("targetAppCode must not blank");
		}
		if (StringUtils.isBlank(key)) {
			throw new LibraClientException("key must not blank");
		}
		System.out.println("==================================================targetAppCode:"+targetAppCode+";key:"+key+";value:"+value);
		getClientService().setAttribute(this, targetAppCode, false, false, key,
				value);
	}

	final public void setSharedAttribute(String key, String value)
			throws LibraClientException {
		if (StringUtils.isBlank(key)) {
			throw new LibraClientException("key must not blank");
		}
		getClientService().setAttribute(this, null, true, false, key, value);
	}

	final public void setDisposableAttribute(String targetAppCode, String key,
			String value) throws LibraClientException {
		if (StringUtils.isBlank(targetAppCode)) {
			throw new LibraClientException("targetAppCode must not blank");
		}
		if (StringUtils.isBlank(key)) {
			throw new LibraClientException("key must not blank");
		}
		getClientService().setAttribute(this, targetAppCode, false, true, key,
				value);
	}

	final public String getAttribute(String srcAppCode, String targetAppCode,
			String key) throws LibraClientException {
		if (StringUtils.isBlank(srcAppCode)) {
			throw new LibraClientException("srcAppCode must not blank");
		}
		if (StringUtils.isBlank(targetAppCode)) {
			throw new LibraClientException("targetAppCode must not blank");
		}
		if (StringUtils.isBlank(key)) {
			throw new LibraClientException("key must not blank");
		}
		return getClientService().getAttribute(this, srcAppCode, targetAppCode,
				false, false, key);
	}

	final public String getSharedAttribute(String srcAppCode, String key)
			throws LibraClientException {
		if (StringUtils.isBlank(srcAppCode)) {
			throw new LibraClientException("srcAppCode must not blank");
		}
		if (StringUtils.isBlank(key)) {
			throw new LibraClientException("key must not blank");
		}
		return getClientService().getAttribute(this, srcAppCode, null, true,
				false, key);
	}

	final public String getDisposableAttribute(String srcAppCode,
			String targetAppCode, String key) throws LibraClientException {
		if (StringUtils.isBlank(srcAppCode)) {
			throw new LibraClientException("srcAppCode must not blank");
		}
		if (StringUtils.isBlank(targetAppCode)) {
			throw new LibraClientException("targetAppCode must not blank");
		}
		if (StringUtils.isBlank(key)) {
			throw new LibraClientException("key must not blank");
		}
		return getClientService().getAttribute(this, srcAppCode, targetAppCode,
				false, true, key);
	}

	// ----------------------------------

	public void setLoginTicket(String loginTicket) {
		this.loginTicket = loginTicket;
	}

	public void setAppCode(String appCode) {
		this.appCode = appCode;
	}

	public void setAppTicket(String appTicket) {
		this.appTicket = appTicket;
	}

	public void setClientTicket(String clientTicket) {
		this.clientTicket = clientTicket;
	}

	public void setRemoteAddr(String remoteAddr) {
		this.remoteAddr = remoteAddr;
	}

	public void setLoginAddr(String loginAddr) {
		this.loginAddr = loginAddr;
	}

//	public void setAppIp(String appIp) {
//		this.appIp = appIp;
//	}
//
//	public void setAppPort(int appPort) {
//		this.appPort = appPort;
//	}

	public void setCustId(String custId) {
		this.custId = custId;
	}

	public void setAttachment(String attachment) {
		this.attachment = attachment;
	}

	public void setCustIdType(String custIdType) {
		this.custIdType = custIdType;
	}

	public void setJumpTicket(String jumpTicket) {
		this.jumpTicket = jumpTicket;
	}

	public String getLoginTicket() {
		return loginTicket;
	}

	public String getAppCode() {
		return appCode;
	}

	public String getAppTicket() {
		return appTicket;
	}

//	public String getAppIp() {
//		return appIp;
//	}
//
//	public int getAppPort() {
//		return appPort;
//	}

	public String getCustId() {
		return custId;
	}

	public String getCustIdType() {
		return custIdType;
	}

	public String getRemoteAddr() {
		return remoteAddr;
	}

	public String getAttachment() {
		return attachment;
	}

	public String getClientTicket() {
		return clientTicket;
	}

	public String getLoginAddr() {
		return loginAddr;
	}

	public String getJumpTicket() {
		return jumpTicket;
	}

	
	//add by zp on 10171024 begin
	private String loginName;
	
	private String userName;
	
	private String menuList;
	
	private String orgList;
	
	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getMenuList() {
		return menuList;
	}

	public void setMenuList(String menuList) {
		this.menuList = menuList;
	}

	public String getOrgList() {
		return orgList;
	}

	public void setOrgList(String orgList) {
		this.orgList = orgList;
	}

	//end
	
}
